import { concatEndTime, concatStartTime } from '@/plugins/date'
import { IFormSchemas, ITableColumns } from '@/type/table'
import { h } from 'vue'
import { ElLink } from 'element-plus'
import UnitSelect from '@/components/unit/UnitSelect.vue'

// 生成列表项
export function generateTableColumn(
  callback?: (columnType: string, row: Record<string, any>) => void,
) {
  const tableColumns: ITableColumns[] = [
    {
      label: '牵头单位',
      prop: 'unitForShort',
      minWidth: 120,
      render: (row) => {
        return h(
          ElLink,
          {
            type: 'primary',
            underline: 'never',
            onClick: () => callback('unitForShort', row),
          },
          () => row.unitForShort,
        )
      },
    },
    {
      label: '办件总数',
      prop: 'matterCount',
      minWidth: 100,
    },
  ]
  return tableColumns
}

// 处理请求参数
export function dealSearchParams(params: any) {
  return {
    ...params,
    startTime: concatStartTime(params?.time?.[0]),
    endTime: concatEndTime(params?.time?.[1]),
  }
}

// 列表查询
export const searchSchame: IFormSchemas[] = [
  {
    label: '牵头单位',
    prop: 'unitId',
    type: (props) => {
      return h(UnitSelect, {
        ...props,
        clearable: true,
        placeholder: '请选择牵头单位',
      })
    },
  },
]
